define(['verifyInput'],function(){
    var currPageObj={};
    currPageObj.init=function(){
        var self = this;

        currPageObj.initEvents();
    };

    //绑定事件
    currPageObj.initEvents=function(){
        var self = this;

        $("#submitBtn").click(function() {
            saveOrEditContent();
        });

        $("#stImg").uploadPreview({ width: 300, height: 200, imgDiv: "#showImg"});
    };
    return currPageObj;
});

function showUpdateType(){
    var currentTypeid = $("#stTypeId").val();
    var data = $.ajax({
        type : 'post',
        url : 'admin/GoodsType/getAllGoodsType.htm',
        data : '',
        cache : false,
        success : function(data) {
            var typeList = data.data;
            var listString = "<option value=\"\"></option>";
            for(var i=0; i<typeList.length; i++){
                var listItem = typeList[i];
                if(currentTypeid == listItem.stTypeId){
                    listString+="<option value=\""+listItem.stTypeId+"\" selected>"+listItem.stTypeName+"</option>"
                }
                else{
                    listString+="<option value=\""+listItem.stTypeId+"\">"+listItem.stTypeName+"</option>"
                }
            }
            $("#stUpdateTypeid").empty();
            $("#stUpdateTypeid").append(listString);

            $(".add .title").text("请选择商品类别");
            $(".tan .tan_min").animate({opacity:1,"margin-top":"0"},600);
            $(".add").fadeIn();
        },
        error : function() {
        }
    });
}

function disshowUpdateType(){
    $(".tan .tan_min").animate({opacity:1,"margin-top":"-500"},600);
    $(".add").fadeOut();
    $(".add .text").val("");
}

function updateGoodsTypeNext(){
    var stTypeid = $("#stUpdateTypeid").val();
    if(stTypeid.trim() == ""){
        alert("请选择商品类别！");
        $("#stUpdateTypeid").focus();
        return false;
    }
    var goodsId = $("#updateGId").val();
    window.location = "admin/goods/goodsEdit.htm?goodsid="+goodsId+"&typeid="+stTypeid;
}


function saveOrEditContent(){
    if(checkInput()){
        $("#mainpageContentForm").submit();
    }

}

function checkInput(){
    var stContentName = $("#stContentName").val();
    if(stContentName.trim() == ""){
        alert("请输入标题！");
        $("#stContentName").focus();
        return false;
    }

    var nmOrder = $("#nmOrder").val();
    if(nmOrder.trim() != ""){
        if(isNaN(nmOrder)){
            alert("请输入数字！");
            $("#nmOrder").focus();
            return false;
        }
    }

    return true;
}

